<html>
<head><meta charset="utf-8"><title>enum_struct_syntax · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/enum_struct_syntax.html">enum_struct_syntax</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212394809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/enum_struct_syntax/near/212394809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haris Muzaffar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/enum_struct_syntax.html#212394809">(Oct 06 2020 at 07:52)</a>:</h4>
<p>When declaring what data an enum can hold, we write an enum like so:</p>
<div class="codehilite"><pre><span></span><code>enum MyEnum {
    Message(String),
    Move{x: u32, y: u32}
}
</code></pre></div>


<p>Why is it syntax error to surround the data of second option i.e. Move with parenthesis like so:</p>
<div class="codehilite"><pre><span></span><code>enum MyEnum {
    Message(String),
    Move({x: u32, y: u32})
}
</code></pre></div>



<a name="212397210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/enum_struct_syntax/near/212397210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/enum_struct_syntax.html#212397210">(Oct 06 2020 at 08:19)</a>:</h4>
<p>within parentheses of an enum variant, you need to specify a type. <code>{x: u32, y: u32}</code> is not valid syntax for a type. It could be syntax for anyonymous structs, but these have a lot of problems of their own</p>



<a name="212397980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/enum_struct_syntax/near/212397980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Haris Muzaffar <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/enum_struct_syntax.html#212397980">(Oct 06 2020 at 08:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/enum_struct_syntax/near/212397210">said</a>:</p>
<blockquote>
<p>within parentheses of an enum variant, you need to specify a type. <code>{x: u32, y: u32}</code> is not valid syntax for a type. It could be syntax for anyonymous structs, but these have a lot of problems of their own</p>
</blockquote>
<p>This makes sense</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>